package com.zzy.order.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zzy.commonutils.JwtUtils;
import com.zzy.commonutils.R;
import com.zzy.order.entity.Order;
import com.zzy.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 订单 前端控制器
 * </p>
 *
 * @author KAZU
 * @since 2023-01-23
 */
@RestController
@RequestMapping("/orderservice/order")
@CrossOrigin
public class OrderController {
	
	@Autowired
	private OrderService orderService;
	
	/**
	 * 生成订单方法
	 * */
	@PostMapping("createOrder/{courseId}")
	public R saveOrder(@PathVariable String courseId,
					   HttpServletRequest request) {
		String orderNo = orderService.createOrders(courseId, JwtUtils.getMemberIdByJwtToken(request));
		return R.ok().data("orderId", orderNo);
	}
	
	/**
	 * 根据订单id查询订单信息
	 * */
	@GetMapping("getOrderInfo/{orderId}")
	public R getOrderInfo(@PathVariable String orderId) {
		QueryWrapper<Order> wrapper = new QueryWrapper<>();
		wrapper.eq("order_no", orderId);
		Order order = orderService.getOne(wrapper);
		return R.ok().data("item", order);
	}
	
}

















